<!DOCTYPE html>
<html>

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>教师端 - 师生学习助手</title>
    <script src="../../static/js/jquery.js"></script>
    <script src="../../static/js/jquery.cookie.js"></script>
    <style>
        /* 页面背景 */
        body {
            background-color: #f4f4f4;
            height: 100vh; /* 使用视口高度 */
            margin: 0;
            display: flex;
            justify-content: center; /* 水平居中 */
            align-items: center; /* 垂直居中 */
            font-family: 'Arial', sans-serif;
        }

        .whole {
            width: 350px;
            padding: 40px;
            background: #fff;
            border-radius: 10px;
            box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
            text-align: center;
        }

        .title {
            font-size: 24px;
            font-weight: bold;
            margin-bottom: 20px;
        }

        .input_tit {
            margin: 10px 0;
            font-weight: bold;
            text-align: left;
        }

        .input_box {
            margin-bottom: 20px;
            text-align: left;
        }

        .radio-group {
            display: flex;
            gap: 20px;
            margin-top: 8px;
        }

        .radio-option {
            display: flex;
            align-items: center;
        }

        .radio-option input {
            margin-right: 5px;
        }

        .finish_btn {
            background-color: #1E9FFF;
            border: none;
            padding: 10px 20px;
            color: white;
            font-size: 16px;
            cursor: pointer;
            width: 100%;
            border-radius: 5px;
        }

        .finish_btn:hover {
            background-color: #1c87d9;
        }

        .input_self {
            width: 100%;
            padding: 10px;
            font-size: 16px;
            border-radius: 5px;
            border: 1px solid #ccc;
            box-sizing: border-box;
        }
        .finish_box {
            margin-top: 20px;
        }
    </style>
</head>

<body class="layui-bg-gray">
<div class="whole">
    <div class="title">师生学习助手</div>
    <form id="form1" class="layui-form">
        <div class="input_tit">角色</div>
        <div class="input_box">
            <div class="radio-group">
                <label class="radio-option">
                    <input type="radio" name="role" value="0" checked> 教师
                </label>
                <label class="radio-option">
                    <input type="radio" name="role" value="1"> 学生
                </label>
            </div>
        </div>
        <div class="input_tit">教工号/学号</div>
        <div class="input_box">
            <input class="input_self layui-input" type="text" name="number" id="number" required placeholder="请输入教工号" />
        </div>
        <div class="input_tit">密码</div>
        <div class="input_box">
            <input class="input_self layui-input" type="password" name="password" id="password" autocomplete="off" required placeholder="请输入密码" />
        </div>
        <div class="finish_box">
            <button type="button" class="finish_btn layui-btn layui-btn-normal" onclick="login()">登录</button>
        </div>
    </form>
</div>

<script type="text/javascript">
    $(function () {
        $(window).on('resize load', function () {
            var win_height = $(window).height();
            var whole_height = $(".whole").height();
            $(".whole").css('top', win_height / 2 - whole_height / 2 - 40 + 'px')
        })
    })

    // 提交登录请求
    function login() {

        var number = $("#number").val();
        var password = $("#password").val();
        var role = $("input[name='role']:checked").val();
        console.log(number, password, role)
        // 老师
        if (role == 0){
            $.ajax({
                url: "teacher/login",  // 地址
                type: "POST",  // 修改为 POST 请求
                data:{
                    "workNumber": number,
                    "password": password
                }, success: function (value) {
                    console.log(value)
                    $.cookie("teacher",value.data.id)
                    $.cookie("teacherName",value.data.name)
                    $.cookie("role",role)
                    $.cookie("teachericon",value.data.icon)
                    console.log(value.data.name)
                    console.log($.cookie("teacherName"))
                    window.location.href="/teacherChat";
                }, error: function (xhr, status, error) {
                    console.error("Error:", error);
                    alert("登录请求失败，请重试。");
                }
            });
        }else{
            $.ajax({
                url: "student/login",  // 地址
                type: "POST",  // 修改为 POST 请求
                data:{
                    "sno": number,
                    "password": password,
                }, success: function (value) {
                    console.log(value)
                    $.cookie("student",value.data.id)
                    $.cookie("studentName",value.data.name)
                    $.cookie("role",role)
                    $.cookie("studenticon",value.data.icon)
                    console.log(value.data.name)
                    window.location.href="/studentChat";
                }, error: function (xhr, status, error) {
                    console.error("Error:", error);
                    alert("登录请求失败，请重试。");
                }
            });
        }

    }
</script>
</body>
</html>